const { ethers } = require('ethers');

// 1. 连接至testnet
let url = "https://testnet-rpc.monad.xyz"
const provider = new ethers.JsonRpcProvider(url)

// 2. 设置合约详情
const contractABI = [{"inputs":[],"name":"checkIn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"checkInCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getCheckInCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastCheckInTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}];
const contractAddress = '0x19c4b1c9B9Aa0543da5904BeFE88abcd1B554748';

// 3. 准备签到账户私钥
// 0xC6d6A2A7b9399d2AAa4b0A026a71219051F3192D
// const privateKey = '0x6bee8d82b3d935e5eeec838a6671b232699141e6559d4c82e3e65c765dfb1f4b'; 

// 0xaE1dAC9Aa2f03Bca12FcC859489bb856B1886857
const privateKey = '0xdf53c77204d96ee72f92592d9de4a13c82813466bd22ecbf74af7cee0c465980'; 

// 4. 连接节点和钱包
const wallet = new ethers.Wallet(privateKey, provider);
const contract = new ethers.Contract(contractAddress, contractABI, wallet);

let acount1_addr = '0xC6d6A2A7b9399d2AAa4b0A026a71219051F3192D'

// 5. 读取签到次数
async function readSignCount() {
  const signCount = await contract.getCheckInCount(acount1_addr);
  console.log("acount sign count:", signCount);
}

// 4. 每日签到
async function dailySignContract() {
  const tx = await contract.checkIn();
  await tx.wait();
  console.log("tx info: ", tx);
}

// 执行
readSignCount();

dailySignContract();